# -*- coding: utf-8 -*-

print("更新版本 V1.0.2")
# 标准库导入

import os
import shutil
import json
import random
import re
import threading
import time
from datetime import datetime

# 第三方库导入
import requests
import pymysql
import pytz

# 自定义模块导入
from airscript.intent import Intent

# Android相关模块导入（通过桥接调用Android API）
# noinspection PyUnresolvedReferences  # 避免IDE误报
from android.net import Uri
from android.provider import Settings
from android.view.animation import DecelerateInterpolator

# ascript安卓脚本框架相关模块
from ascript.android import action, system
from ascript.android.node import Selector
from ascript.android.system import Device, KeyValue, R

# 加载插件
from ascript.android import plug
plug.load("deepseek")

# deepseek插件导入
from deepseek import DeepSeek


url = f'https://gitee.com/liang_shanshui/dyuser/raw/master/res/main.py?t={int(time.time())}'

try:
    r = requests.get(url, timeout=10)
    print(f"请求状态码: {r.status_code}")
    if r.status_code == 200:
        print(f"拉取内容长度: {len(r.text)}")
        current_file = os.path.abspath(__file__)
        print(f"当前文件路径: {current_file}")
        backup_file = current_file + '.bak'

        # 备份当前文件
        shutil.copy2(current_file, backup_file)
        print(f"已备份当前文件到 {backup_file}")

        # 写入远程最新代码覆盖当前文件
        with open(current_file, 'w', encoding='utf-8') as f:
            f.write(r.text)
        print("已更新本地文件内容。")

        # 执行远程代码（刚写入的代码）
        exec(r.text)
    else:
        print("拉取远程代码失败，未更新。")
except Exception as e:
    print(f"更新过程中发生异常: {e}")
